package longrise.phone.com.bjjt_jyb.compensate;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.IdRes;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.FormParameter;
import com.longrise.android.FrameworkManager;
import com.longrise.android.ILFMsgListener;
import com.longrise.android.LFView;
import com.longrise.android.loaddata.newloaddata.LoadDataManagerCar;
import com.longrise.android.loaddata.newloaddata.LoadDataManagerFather;

import java.text.ParseException;

import longrise.phone.com.bjjt_jyb.Application.BaseApplication;
import longrise.phone.com.bjjt_jyb.Constant.URLConstant;
import longrise.phone.com.bjjt_jyb.R;
import longrise.phone.com.bjjt_jyb.Utils.CheckCard;
import longrise.phone.com.bjjt_jyb.Utils.CommontUtils;
import longrise.phone.com.bjjt_jyb.Utils.StringUtils;
import longrise.phone.com.bjjt_jyb.Utils.UiUtil;
import longrise.phone.com.bjjt_jyb.Utils.UiUtils;
import longrise.phone.com.bjjt_jyb.widget.SetTextModule;


/**
 * 事故上传的信息填写界面，Created by Administrator on 2016/5/12.
 */
public class AccidentLoadingViewNew extends LFView implements View.OnClickListener, ILFMsgListener, RadioGroup.OnCheckedChangeListener {
    private String appCaseNo;//案件编号
    private Context context = null;
    private View view = null;
    private Button bt_accidentloading_new;
    private BaseApplication mApplication;
    private Dialog processDialog;
    private String jfCarType;
    private String yfCarType;
    private LinearLayout hn_btn_back;
    private String accidentType;
    private String discription;
    private boolean checked;
    private String imageaddress;
    private RadioGroup radioGroupMotorVehiclePartyJ;
    private RadioGroup radioGroupnotMotorVehiclePartyY;
    private SetTextModule stv_MotorVehicle_chooseCartypePartyJ;
    private SetTextModule stv_MotorVehicle_NamePartyJ;
    private SetTextModule stv_MotorVehicle_carNoPartyJ;
    private TextView motorVehicle_provinceFirstViewPartyJ;
    private SetTextModule stv_MotorVehicle_carFrameNoPartyJ;
    private SetTextModule stv_MotorVehicle_PhonePartyJ;
    private SetTextModule stv_MotorVehicle_IDPartyJ;
    private SetTextModule stv_MotorVehicle_InsurancePartyJ;
    private TextView gainTextViewPartyJ;
    private SetTextModule stv_notMotorVehicle_chooseCartypePartyY;
    private SetTextModule stv_notMotorVehicle_NamePartyY;
    private SetTextModule stv_notMotorVehicle_carBrandY;
    private SetTextModule stv_notMotorVehicle_PhonePartyY;
    private SetTextModule stv_notMotorVehicle_IDPartyY;
    private boolean test = false;//测试内网时置为true；

    public AccidentLoadingViewNew(Context context, String appCaseNo, String accidentType, String discription) {
        super(context);
        this.context = context;
        this.appCaseNo = appCaseNo;
        this.mApplication = (BaseApplication) context.getApplicationContext();
        this.accidentType = accidentType;
        this.discription = discription;
    }

    @Override
    public void refreshByTime() {

    }

    @Override
    public FormParameter getFormParameter() {
        FormParameter fp = new FormParameter();
        fp.setShowtitle(false);
        return fp;
    }

    @Override
    public void refresh() {
    }

    @Override
    public View getView() {
        return view;
    }

    @Override
    public void init() {
        initView();
        regEvent(true);
        pictureRecognitionData();
    }

    private void initView() {
        view = View.inflate(context, R.layout.view_accidentloadingnew, null);
        hn_btn_back = (LinearLayout) view.findViewById(R.id.hn_btn_back);
        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        tv_title.setText("事故上传");
        bt_accidentloading_new = (Button) view.findViewById(R.id.bt_accidentloading_new);
        //甲方选择车型
        stv_MotorVehicle_chooseCartypePartyJ = (SetTextModule) view.findViewById(R.id.stv_MotorVehicle_chooseCartypePartyJ);
        radioGroupMotorVehiclePartyJ = stv_MotorVehicle_chooseCartypePartyJ.getRadioGroup();
        //甲方姓名
        stv_MotorVehicle_NamePartyJ = (SetTextModule) view.findViewById(R.id.stv_MotorVehicle_NamePartyJ);
        stv_MotorVehicle_NamePartyJ.setTextModleParameter("姓名");
        //甲方车牌
        stv_MotorVehicle_carNoPartyJ = (SetTextModule) view.findViewById(R.id.stv_MotorVehicle_carNoPartyJ);
        motorVehicle_provinceFirstViewPartyJ = stv_MotorVehicle_carNoPartyJ.getProvinceFirstView();
        //甲方车架
        stv_MotorVehicle_carFrameNoPartyJ = (SetTextModule) view.findViewById(R.id.stv_MotorVehicle_carFrameNoPartyJ);
        stv_MotorVehicle_carFrameNoPartyJ.setTextModleParameter("车架号");
        //甲方联系电话
        stv_MotorVehicle_PhonePartyJ = (SetTextModule) view.findViewById(R.id.stv_MotorVehicle_PhonePartyJ);
        stv_MotorVehicle_PhonePartyJ.setTextModleParameter("联系电话");
        //甲方驾驶证号
        stv_MotorVehicle_IDPartyJ = (SetTextModule) view.findViewById(R.id.stv_MotorVehicle_IDPartyJ);
        stv_MotorVehicle_IDPartyJ.setTextModleParameter("驾驶证号");
        //甲方获取保单号
        stv_MotorVehicle_InsurancePartyJ = (SetTextModule) view.findViewById(R.id.stv_MotorVehicle_InsurancePartyJ);
        gainTextViewPartyJ = stv_MotorVehicle_InsurancePartyJ.getGainTextView();
        //乙方选择车型
        stv_notMotorVehicle_chooseCartypePartyY = (SetTextModule) view.findViewById(R.id.stv_notMotorVehicle_chooseCartypePartyY);
        radioGroupnotMotorVehiclePartyY = stv_notMotorVehicle_chooseCartypePartyY.getRadioGroup();
        //乙方姓名
        stv_notMotorVehicle_NamePartyY = (SetTextModule) view.findViewById(R.id.stv_notMotorVehicle_NamePartyY);
        stv_notMotorVehicle_NamePartyY.setTextModleParameter("姓名");
        //乙方车辆品牌
        stv_notMotorVehicle_carBrandY = (SetTextModule) view.findViewById(R.id.stv_notMotorVehicle_carBrandY);
        stv_notMotorVehicle_carBrandY.setTextModleParameter("车辆品牌");
        //乙方电话
        stv_notMotorVehicle_PhonePartyY = (SetTextModule) view.findViewById(R.id.stv_notMotorVehicle_PhonePartyY);
        stv_notMotorVehicle_PhonePartyY.setTextModleParameter("联系电话");
        //乙方电话
        stv_notMotorVehicle_IDPartyY = (SetTextModule) view.findViewById(R.id.stv_notMotorVehicle_IDPartyY);
        stv_notMotorVehicle_IDPartyY.setTextModleParameter("身份证号");
    }

    private void regEvent(boolean b) {
        if (null != hn_btn_back) {
            hn_btn_back.setOnClickListener(b ? this : null);
        }
        if (null != bt_accidentloading_new) {
            bt_accidentloading_new.setOnClickListener(b ? this : null);
        }
        if (null != motorVehicle_provinceFirstViewPartyJ) {
            motorVehicle_provinceFirstViewPartyJ.setOnClickListener(b ? this : null);
        }
        if (null != gainTextViewPartyJ) {
            gainTextViewPartyJ.setOnClickListener(b ? this : null);
        }
        if (null != radioGroupMotorVehiclePartyJ) {
            radioGroupMotorVehiclePartyJ.setOnCheckedChangeListener(b ? this : null);
        }
        if (null != radioGroupnotMotorVehiclePartyY) {
            radioGroupnotMotorVehiclePartyY.setOnCheckedChangeListener(b ? this : null);
        }
        if (b) {
            this.addILFMsgListener(this);
        } else {
            this.removeILFMsgListener(this);
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
        if (radioGroup == radioGroupMotorVehiclePartyJ) {
            if (i == stv_MotorVehicle_chooseCartypePartyJ.getRadioButtonOneId()) {
                jfCarType = "1";
            } else if (i == stv_MotorVehicle_chooseCartypePartyJ.getRadioButtonTwoId()) {
                jfCarType = "2";
            }
        } else if (radioGroup == radioGroupnotMotorVehiclePartyY) {
            if (i == stv_notMotorVehicle_chooseCartypePartyY.getRadioButtonOneId()) {
                yfCarType = "3";
            } else if (i == stv_notMotorVehicle_chooseCartypePartyY.getRadioButtonTwoId()) {
                yfCarType = "4";
            } else if (i == stv_notMotorVehicle_chooseCartypePartyY.getRadioButtonThreeId()) {
                yfCarType = "5";
            }
        }
    }

    @Override
    public void onClick(View v) {
        String carjfirst = stv_MotorVehicle_carNoPartyJ.getProvinceText();
        String carJ = carjfirst + stv_MotorVehicle_carNoPartyJ.getProvinceNext().toUpperCase();//甲方车牌号
        String carNoJ = stv_MotorVehicle_carFrameNoPartyJ.getTextModuleText().toUpperCase();//甲方车架号
        if (v.getId() == motorVehicle_provinceFirstViewPartyJ.getId()) {
            stv_MotorVehicle_carNoPartyJ.showPop();
        }
        if (v.getId() == gainTextViewPartyJ.getId()) {
            //获取保单号
            stv_MotorVehicle_InsurancePartyJ.setGainText("");
            String car1 = stv_MotorVehicle_carNoPartyJ.getProvinceNext();
            getBxNumber(car1, carJ, carNoJ, stv_MotorVehicle_carNoPartyJ.getGainEdittext());
        }
        switch (v.getId()) {
            case R.id.hn_btn_back:
                showHomeView();
                break;

            case R.id.bt_accidentloading_new:
                String phoneJ = stv_MotorVehicle_PhonePartyJ.getTextModuleText();//甲方手机号
                String IDCardJ = stv_MotorVehicle_IDPartyJ.getTextModuleText();//甲方驾驶证号
                String phoneY = stv_notMotorVehicle_PhonePartyY.getTextModuleText();//乙方手机号
                String IDCardY = stv_notMotorVehicle_IDPartyY.getTextModuleText();//乙方驾驶证号
                checked = stv_MotorVehicle_carNoPartyJ.isChecked();
                String trim = stv_MotorVehicle_carNoPartyJ.getProvinceText();
                if (!ifEdittextNull()) {
                    return;
                }
                //甲方验证
                if (!StringUtils.isCar(carJ)) {
                    UiUtil.showToast(context, "甲方车牌号错误");
                    return;
                }
                if (!trim.equals("豫") || checked) {
                    if (!CommontUtils.isCarvin(carNoJ)) {
                        UiUtil.showToast(context, "甲方车架号错误");
                        return;
                    }
                }
                if (!StringUtils.isPhone(phoneJ)) {
                    UiUtil.showToast(context, "甲方联系电话错误");
                    return;
                }
                try {
                    if (!CheckCard.IDCardValidate(IDCardJ)) {
                        UiUtil.showToast(context, "甲方驾驶证号错误");
                        return;
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                if (!StringUtils.isPhone(phoneY)) {
                    UiUtil.showToast(context, "乙方联系电话错误");
                    return;
                }
                try {
                    if (!CheckCard.IDCardValidate(IDCardY)) {
                        UiUtil.showToast(context, "乙方身份证号错误");
                        return;
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                //判断双方的手机号是否相同
                if (phoneY.equals(phoneJ)) {
                    UiUtil.showToast(context, "事故双方联系电话相同");
                    return;
                }
                //判断双方的车架号是否相同
                if (IDCardJ.equals(IDCardY)) {
                    UiUtil.showToast(context, "事故双方驾驶证号相同");
                    return;
                }
                if (!trim.equals("豫") || checked) {
                    showDialog("请人工核实临牌或省外车辆的证件信息真伪");
                    return;
                } else {
                    testingCarNum();
                }
                break;
            //提交
            //submit();
        }
    }

    private void showDialog(String s) {
        UiUtils.showDialog(context, R.mipmap.warn, null, s, "人工核实", "认可提交",
                new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                    }
                }, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        testingCarNum();
                    }
                });
    }

    /**
     * 验证车牌是否有交强险信息
     */
    private void testingCarNum() {
        try {
            processDialog = UiUtil.showProcessDialog(context, "加载数据中...");
            EntityBean[] casecarlist;//车主信息数组
            EntityBean bean = new EntityBean();
            bean.set("appcaseno", appCaseNo);
            EntityBean yfBean = new EntityBean();// 乙方数据
            String myName = stv_notMotorVehicle_NamePartyY.getTextModuleText(); // 车主姓名
            yfBean.set("carownname", myName);
            yfBean.set("carownphone", stv_notMotorVehicle_PhonePartyY.getTextModuleText()); //手机号
            yfBean.set("driverlicence", stv_notMotorVehicle_IDPartyY.getTextModuleText());
            yfBean.set("cartype", yfCarType); // 车型
            yfBean.set("frameno", stv_notMotorVehicle_carBrandY.getTextModuleText());//车辆品牌
            yfBean.set("cardno", stv_notMotorVehicle_IDPartyY.getTextModuleText()); //身份证
            yfBean.set("drivernoimg", ""); //驾驶证照片
            yfBean.set("drivingnoimg", "");  //行驶证照片
            yfBean.set("party", "0");
            EntityBean jfBean = new EntityBean();// 甲方数据
            jfBean.set("carownname", stv_MotorVehicle_NamePartyJ.getTextModuleText());
            jfBean.set("carownphone", stv_MotorVehicle_PhonePartyJ.getTextModuleText());
            jfBean.set("casecarno", stv_MotorVehicle_NamePartyJ.getCarNo());  // 案件车牌号
            jfBean.set("cartype", jfCarType); // 车型
            jfBean.set("frameno", stv_MotorVehicle_carFrameNoPartyJ.getTextModuleText());  //车架号
            jfBean.set("cardno", stv_MotorVehicle_IDPartyJ.getTextModuleText()); //身份证
            jfBean.set("trafficinsno", stv_MotorVehicle_carNoPartyJ.getGainText()); //保单号
            jfBean.set("drivernoimg", ""); //驾驶证照片
            jfBean.set("drivingnoimg", ""); //行驶证照片
            if (checked) {
                jfBean.set("temporary", "1");//1为临时车牌
            } else {
                jfBean.set("temporary", "0");
            }
            jfBean.set("driverlicence", stv_MotorVehicle_IDPartyJ.getTextModuleText());
            jfBean.set("party", "1");//区分甲方乙方，甲方是1
            casecarlist = new EntityBean[]{yfBean, jfBean};
            bean.set("casecarlist", casecarlist);
            LoadDataManagerCar.getInstance(context).callService(null,
                    mApplication.getServerUrl(), URLConstant.JJAPPCHECKCBXX, bean, new LoadDataManagerFather.OnRequestCompleteListener() {
                        @Override
                        public void onSuccess(String key, String service, Object result) {
                            if (null != processDialog) {
                                if (processDialog.isShowing()) {
                                    processDialog.dismiss();
                                }
                            }
                            EntityBean bean = (EntityBean) result;
                            String restate = bean.getString("restate");
                            String redes = bean.getString("redes");
                            if ("1".equals(restate)) {
                                submit();
                            } else {
                                showsingle(context, redes);
                            }
                        }

                        @Override
                        public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {
                            if (null != processDialog) {
                                if (processDialog.isShowing()) {
                                    processDialog.dismiss();
                                }
                            }
                            UiUtil.showToast(context, "连接超时，请检查网络后重试。");
                        }

                        @Override
                        public void onFinished(String key, String service) {
                            if (null != processDialog) {
                                if (processDialog.isShowing()) {
                                    processDialog.dismiss();
                                }
                            }
                        }
                    });
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    private void showsingle(final Context context, String redes) {
        UiUtils.showSingleDialog(context, R.mipmap.a_32, redes, "确认", new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }

    //创造双方的bean跳转,这是责任认定书的bean[]
    private void submit() {
        EntityBean hisBean = new EntityBean();
        hisBean.set("carType", jfCarType);
        hisBean.set("carownname", stv_MotorVehicle_NamePartyJ.getTextModuleText());
        hisBean.set("casecarno", stv_MotorVehicle_NamePartyJ.getCarNo());//甲方车牌号
        hisBean.set("casecarphone", stv_MotorVehicle_PhonePartyJ.getTextModuleText());
        hisBean.set("casecarId", stv_MotorVehicle_IDPartyJ.getTextModuleText());
        hisBean.set("frameno", stv_MotorVehicle_carFrameNoPartyJ.getTextModuleText());
        hisBean.set("trafficinsno", stv_MotorVehicle_carNoPartyJ.getGainText());//保单号

        EntityBean myBean = new EntityBean();
        myBean.set("carownname", stv_notMotorVehicle_NamePartyY.getTextModuleText());
        myBean.set("casecarId", stv_notMotorVehicle_IDPartyY.getTextModuleText());//驾驶证号
        myBean.set("casecarphone", stv_notMotorVehicle_PhonePartyY.getTextModuleText());//联系电话
        myBean.set("accidentType", accidentType);
        myBean.set("discription", discription);
        myBean.set("appCaseNo", appCaseNo);
        myBean.set("carType", yfCarType);
        myBean.set("frameno", stv_notMotorVehicle_carBrandY.getTextModuleText());
        EntityBean[] disputeBean = new EntityBean[]{hisBean, myBean};
        DisputeView disputeview = new DisputeView(context, disputeBean, 3);
        FrameworkManager.getInstance().showNewForm(context, disputeview);
    }

    /**
     * 判断输入框是否为空
     */
    private boolean ifEdittextNull() {
        String et_accidentloadingpic1_newcontent = stv_MotorVehicle_NamePartyJ.getTextModuleText();
        String et_accidentloadingpic2_newcontent = stv_MotorVehicle_carNoPartyJ.getProvinceNext();
        String et_accidentloadingpic3_newcontent = stv_MotorVehicle_PhonePartyJ.getTextModuleText();
        String et_accidentloadingpic5_newcontent = stv_notMotorVehicle_NamePartyY.getTextModuleText();
        String et_accidentloadingpictwo_newcontent =stv_notMotorVehicle_IDPartyY.getTextModuleText();
        String et_accidentcarnum1_newcontent = stv_MotorVehicle_carFrameNoPartyJ.getTextModuleText();//甲方车架号
        String et_accidentcarnum2_newcontent =  stv_notMotorVehicle_carBrandY.getTextModuleText();//乙方车架号
        String et_accdentidcardhe_newcontent = stv_MotorVehicle_IDPartyJ.getTextModuleText();
        String et_accdentidcardme_newcontent =  stv_notMotorVehicle_IDPartyY.getTextModuleText();
        if (!TextUtils.isEmpty(et_accidentloadingpic1_newcontent) && !TextUtils.isEmpty(et_accidentloadingpic2_newcontent)
                && !TextUtils.isEmpty(jfCarType) && !TextUtils.isEmpty(yfCarType)
                && !TextUtils.isEmpty(et_accidentloadingpic5_newcontent) && !TextUtils.isEmpty(et_accdentidcardhe_newcontent)
                && !TextUtils.isEmpty(et_accdentidcardme_newcontent) && !TextUtils.isEmpty(et_accidentcarnum1_newcontent)
                && !TextUtils.isEmpty(et_accidentcarnum2_newcontent) && !TextUtils.isEmpty(et_accidentloadingpictwo_newcontent)) {
            return true;
        } else if (TextUtils.isEmpty(jfCarType)) {
            UiUtil.showToast(context, "请甲方选择车辆类型");
            return false;
        } else if (TextUtils.isEmpty(et_accidentloadingpic1_newcontent)) {
            UiUtil.showToast(context, "甲方姓名为空");
            return false;
        } else if (TextUtils.isEmpty(et_accidentloadingpic2_newcontent)) {
            UiUtil.showToast(context, "甲方车牌号为空");
            return false;
        } else if (TextUtils.isEmpty(et_accidentcarnum1_newcontent)) {
            UiUtil.showToast(context, "甲方车架号为空");
            return false;
        } else if (TextUtils.isEmpty(et_accidentloadingpic3_newcontent)) {
            UiUtil.showToast(context, "甲方联系电话为空");
            return false;
        } else if (TextUtils.isEmpty(et_accdentidcardhe_newcontent)) {
            UiUtil.showToast(context, "甲方驾驶证号为空");
            return false;
        } else if (TextUtils.isEmpty(yfCarType)) {
            UiUtil.showToast(context, "请乙方选择车辆类型");
            return false;
        } else if (TextUtils.isEmpty(et_accidentloadingpic5_newcontent)) {
            UiUtil.showToast(context, "乙方姓名为空");
            return false;
        } else if (TextUtils.isEmpty(et_accidentcarnum2_newcontent)) {
            UiUtil.showToast(context, "乙方车辆品牌为空");
            return false;
        } else if (TextUtils.isEmpty(et_accidentloadingpictwo_newcontent)) {
            UiUtil.showToast(context, "乙方联系电话为空");
            return false;
        } else if (TextUtils.isEmpty(et_accdentidcardme_newcontent)) {
            UiUtil.showToast(context, "乙方身份证号为空");
            return false;
        }
        return false;
    }

    @Override
    public Object onLFMsg(int i, Object... objects) {
        if (i == -10) {//点击返回按键
            showHomeView();
        }
        return false;
    }

    @Override
    public void OnDestroy() {
        super.OnDestroy();
        view = null;
        myHandler = null;
        regEvent(false);
        closeForm();
    }

    /**
     * 提示是否不继续处理，返回首页
     */
    private void showHomeView() {
        UiUtils.showDialog(context, null, null, "是否放弃输入，结束本次快处并返回首页", "返回", "确认",
                new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                    }
                }, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        closeAllForm();
                        OnDestroy();
                        HomePageView homepageview = new HomePageView(context);
                        FrameworkManager.getInstance().showNewForm(context, homepageview);
                    }
                });
    }


    // 获取保单号
    private void getBxNumber(String car, String carno, String framno, final EditText view) {
        try {
            if (TextUtils.isEmpty(car)) {
                UiUtil.showToast(context, "请填写车牌号");
                return;
            }
            if (TextUtils.isEmpty(framno)) {
                UiUtil.showToast(context, "请填写车架号");
                return;
            }
            processDialog = UiUtil.showProcessDialog(context, "加载数据中...");
            EntityBean bean = new EntityBean();
            bean.set("userflag", mApplication.getKckpName());
            bean.set("token", mApplication.getToken());
            bean.set("casecarno", carno);
            bean.set("appcaseno", appCaseNo);
            bean.set("policyno", "");
            bean.set("frameno", framno.toUpperCase());
            LoadDataManagerCar.getInstance(context).callService(null,
                    mApplication.getServerUrl(), URLConstant.JJAPPKCKPSEARCHCPSNUM, bean, new LoadDataManagerFather.OnRequestCompleteListener() {
                        @Override
                        public void onSuccess(String key, String service, Object result) {
                            if (null != processDialog) {
                                if (processDialog.isShowing()) {
                                    processDialog.dismiss();
                                }
                            }
                            EntityBean bean = (EntityBean) result;
                            String restate = bean.getString("restate");
                            if ("1".equals(restate)) {
                                EntityBean data = bean.getBean("data");
                                String isValid = data.getString("isVaild");
                                if ("0".equals(isValid)) {
                                    String trafficinsno = data.getString("trafficinsno");
                                    view.setTextSize(12);
                                    view.setText(trafficinsno);
                                }
                            } else {
                                String error = bean.getString("redes");
                                UiUtil.showToast(context, error);
                            }
                        }

                        @Override
                        public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {
                            if (null != processDialog) {
                                if (processDialog.isShowing()) {
                                    processDialog.dismiss();
                                }
                            }
                            UiUtil.showToast(context, "连接超时，请检查网络后重试。");
                        }

                        @Override
                        public void onFinished(String key, String service) {
                            if (null != processDialog) {
                                if (processDialog.isShowing()) {
                                    processDialog.dismiss();
                                }
                            }
                        }
                    });
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    private Handler myHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (view == null) {
                return;
            }
            if (msg.what == 0003) {
                //初始化信息，从拍照界面返的信息
                EntityBean jfJszBean = mApplication.getJfJszBean_new();//甲方驾驶证
                if (null != jfJszBean) {
                    String ocrname = jfJszBean.getString("ocrname");//姓名
                    String ocrcardno = jfJszBean.getString("ocrcardno");//驾驶证号
                    if (null != ocrname) {
                        stv_MotorVehicle_NamePartyJ.setText(ocrname);
                    }
                    if (null != ocrcardno) {
                        stv_MotorVehicle_IDPartyJ.setText(ocrcardno);
                    }
                }
                EntityBean jfXszBean = mApplication.getJfXszBean_new();//甲方行驶证
                if (null != jfXszBean) {
                    String ocrvin = jfXszBean.getString("ocrvin");//车架号
                    String ocrcarno = jfXszBean.getString("ocrcarno");//车牌号
                    if (null != ocrvin) {
                        stv_MotorVehicle_carFrameNoPartyJ.setText(ocrvin);
                    }
                    if (null != ocrcarno && StringUtils.isCar(ocrcarno)) {//车牌正确才
                        stv_MotorVehicle_NamePartyJ.getProvinceFirstView().setText(ocrcarno.substring(0, 1));
                        stv_MotorVehicle_NamePartyJ.getProvinceNextView().setText(ocrcarno.substring(1, 7));
                    }
                }
                EntityBean yfJszBean = mApplication.getYfJszBean_new();//乙方驾驶证
                if (null != yfJszBean) {
                    String ocrname = yfJszBean.getString("name");//姓名
                    String ocrcardno = yfJszBean.getString("cardno");//驾驶证号
                    if (null != ocrname) {
                        stv_notMotorVehicle_NamePartyY.setText(ocrname);
                    }
                    if (null != ocrcardno) {
                        stv_notMotorVehicle_IDPartyY.setText(ocrcardno);
                    }
                }
                EntityBean yfXszBean = mApplication.getYfXszBean_new();//乙方行驶证
                if (null != yfXszBean) {
                    String ocrvin = yfXszBean.getString("ocrvin");//车架号
                    if (null != ocrvin) {
                        stv_notMotorVehicle_carBrandY.setText(ocrvin);
                    }
                }
            }
        }
    };

    // 调取照片识别的接口
    private void pictureRecognitionData() {
        try {
            processDialog = UiUtil.showProcessDialog(context, "加载数据中...");
            EntityBean bean = new EntityBean();
            String userName = mApplication.getLoginInfo().getBean("userinfo")
                    .getString("userflag");
            bean.set("appcaseno", appCaseNo);
            bean.set("userflag", userName);
            bean.set("token", mApplication.getToken());
            LoadDataManagerCar.getInstance(context).callService(null,
                    mApplication.getServerUrl(), URLConstant.JJAPPGETOCRDATA, bean, new LoadDataManagerFather.OnRequestCompleteListener() {
                        @Override
                        public void onSuccess(String key, String service, Object result) {
                            if (null != processDialog) {
                                if (processDialog.isShowing()) {
                                    processDialog.dismiss();
                                }
                            }
                            EntityBean bean = (EntityBean) result;
                            String restate = bean.getString("restate");
                            String redes = bean.getString("redes");
                            imageaddress = bean.getString("imageaddress");
                            EntityBean[] cardata = bean.getBeans("data");
                            if ("1".equals(restate)) {
                                if (null != cardata) {
                                    for (EntityBean element : cardata) {
                                        String imagetype = element.getString("imagetype");
                                        if ("6".equals(imagetype)) {//甲驾驶证
                                            mApplication.setJfJszBean_new(element);
                                        } else if ("7".equals(imagetype)) {//甲方行驶证
                                            mApplication.setJfXszBean_new(element);
                                        } else if ("18".equals(imagetype)) {//乙方驾驶证
                                            mApplication.setYfJszBean_new(element);
                                        } else if ("19".equals(imagetype)) {//乙方行驶证
                                            mApplication.setYfXszBean_new(element);
                                        }
                                    }
                                }
                                if (myHandler != null) {
                                    myHandler.sendEmptyMessage(0003);
                                }
                            } else {
                                UiUtil.showToast(context, redes);
                            }
                        }

                        @Override
                        public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {
                            if (null != processDialog) {
                                if (processDialog.isShowing()) {
                                    processDialog.dismiss();
                                }
                            }
                            UiUtil.showToast(context, "连接超时，请检查网络后重试。");
                        }

                        @Override
                        public void onFinished(String key, String service) {
                            if (null != processDialog) {
                                if (processDialog.isShowing()) {
                                    processDialog.dismiss();
                                }
                            }
                        }
                    });
        } catch (Exception e) {

            e.printStackTrace();
        }
    }


}
